package bdd.sql.server.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Bean Keystore.
 * @author Guillaume Pocas & Jean-Fraçois Augé
 */
@Entity
@Table(name = "kraken_keystore")
public class Keystore {

	@Id
	@GeneratedValue
	@Column(name = "key_id")
	private int key_id;
	
	@Column(name = "key_name", nullable = false, updatable = false, unique = true)
	private String key_name;
	
	@Column(name = "key_path", nullable = false, updatable = true, unique = true)
	private String key_path;
	
	@Column(name = "key_iv", nullable = false, updatable = false, unique = true)
	private byte[] key_iv;
	
	@Column(name = "key_password", nullable = false, updatable = false, unique = true)
	private char[] key_password;
	
	@Column(name = "key_containedKeyPassword", nullable = false, updatable = false, unique = true)
	private char[] key_containedKeyPassword;
	
	@Column(name = "key_alias", nullable = false, updatable = false, unique = true)
	private String key_alias;
	
	@Column(name = "key_weight", nullable = true, updatable = true, unique = false)
	private long key_weight;
	
	@Column(name = "key_usedForStorage", nullable = true, updatable = true, unique = false)
	private boolean key_usedForStorage;
	
	@Column(name = "key_user", nullable = true, updatable = true, unique = true)
	private String key_user;
	
	@Column(name = "key_keystore", columnDefinition = "varbinary(max)", nullable = false, updatable = false, unique = true)
	private byte[] key_keystore;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "key_video", nullable = true, updatable = true, unique = false)
	private Video video;
	
	@OneToOne
	@JoinColumn(name = "key_auth", nullable = true, updatable = true, unique = true)
	private ServerAuth auth;
	
	@OneToOne
	@JoinColumn(name = "key_site", nullable = true, updatable = true, unique = true)
	private ServerSite site;
	
	@OneToOne
	@JoinColumn(name = "key_storage", nullable = true, updatable = true, unique = true)
	private ServerStorage storage;
	
	/**
	 * Constructeur vide.
	 */
	public Keystore() {}
	
	/**
	 * Créer un nouveau Keystore.
	 */
	public Keystore(String name, String path, byte[] iv, char[] ksPass, char[] keyPassword, String alias, long weight, boolean usedForStorage, String user, byte[] keystore) {
		this.key_name = name;
		this.key_path = path;
		this.key_iv = iv;
		this.key_password = ksPass;
		this.key_containedKeyPassword = keyPassword;
		this.key_alias = alias;
		this.key_weight = weight;
		this.key_usedForStorage = usedForStorage;
		this.key_user = user;
		this.key_keystore = keystore;
	}
	
	public Keystore(String name, String path, byte[] iv, char[] ksPass, char[] keyPassword, String alias, long weight, boolean usedForStorage, String user, byte[] keystore, Video video) {
		this.key_name = name;
		this.key_path = path;
		this.key_iv = iv;
		this.key_password = ksPass;
		this.key_containedKeyPassword = keyPassword;
		this.key_alias = alias;
		this.key_weight = weight;
		this.key_usedForStorage = usedForStorage;
		this.key_user = user;
		this.key_keystore = keystore;
		this.video = video;
	}
	
	public int getKey_id() {	return key_id;	}
	public void setKey_id(int key_id) {	this.key_id = key_id;	}

	public String getKey_name() {	return key_name;	}
	public void setKey_name(String key_name) {	this.key_name = key_name;	}

	public String getKey_path() {	return key_path;	}
	public void setKey_path(String key_path) {	this.key_path = key_path;	}

	public byte[] getKey_iv() {	return key_iv;	}
	public void setKey_iv(byte[] key_iv) {	this.key_iv = key_iv;	}

	public char[] getKey_password() {	return key_password;	}
	public void setKey_password(char[] key_password) {	this.key_password = key_password;	}

	public char[] getKey_containedKeyPassword() {	return key_containedKeyPassword;	}
	public void setKey_containedKeyPassword(char[] key_containedKeyPassword) {	this.key_containedKeyPassword = key_containedKeyPassword;	}

	public String getKey_alias() {	return key_alias;	}
	public void setKey_alias(String key_alias) {	this.key_alias = key_alias;	}

	public long getKey_weight() {	return key_weight;	}
	public void setKey_weight(long key_weight) {	this.key_weight = key_weight;	}

	public boolean isKey_usedForStorage() {	return key_usedForStorage;	}
	public void setKey_usedForStorage(boolean key_usedForStorage) {	this.key_usedForStorage = key_usedForStorage;	}

	public String getKey_user() {	return key_user;	}
	public void setKey_user(String key_user) {	this.key_user = key_user;	}

	public byte[] getKey_keystore() {	return key_keystore;	}
	public void setKey_keystore(byte[] key_keystore) {	this.key_keystore = key_keystore;	}

	public Video getVideo() {	return video;	}
	public void setVideo(Video video) {	this.video = video;	}

	public ServerAuth getAuth() {	return auth;	}
	public void setAuth(ServerAuth auth) {	this.auth = auth;	}

	public ServerSite getSite() {	return site;	}
	public void setSite(ServerSite site) {	this.site = site;	}

	public ServerStorage getStorage() {	return storage;	}
	public void setStorage(ServerStorage storage) {	this.storage = storage;	}

	@Override
	public String toString(){ return String.valueOf(this.getKey_id());	}
	
}